package edu.odu.cs.sstore;

import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import edu.odu.cs.sstore.service.Bootstrap;

public class SecureStore implements Runnable {

	private ClassPathXmlApplicationContext ctx;
	
	private static final String DEFAULT_RMI_REGISTRY_PORT = "1199";
	
	public static void main(String[] args) throws IOException {
		
		if(System.getProperty("javax.rmi.ssl.client.enabledCipherSuites") == null)
			System.setProperty("javax.rmi.ssl.client.enabledCipherSuites", "SSL_DH_anon_WITH_RC4_128_MD5");
		
		if(System.getProperty("javax.rmi.ssl.client.enabledProtocols") == null)
			System.setProperty("javax.rmi.ssl.client.enabledProtocols", "TLSv1");
		
		System.setProperty("sstore.rmi.registryport",DEFAULT_RMI_REGISTRY_PORT);
		
		System.out.println(System.getProperty("java.security.policy"));

		SecureStore s = new SecureStore();
		new Thread(s).start();
	}
	
	public SecureStore() {
		
		// open/read the application context file
	    ctx = new ClassPathXmlApplicationContext("META-INF/spring/app-context.xml");
		
	    // TODO - find a SPRING way to call this upon creation of the IoC container....
		Bootstrap bootstrap = ctx.getBean(Bootstrap.class);
		bootstrap.execute();
		
	}

	public void run() {
		while (true) {
			synchronized (this) {
				try {
					this.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
